package com.lcxw.hxzbapi.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcxw.hxzbapi.dao.mapper.TixianMapper;
import com.lcxw.hxzbapi.entity.pojo.Tixian;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class TixianService {

    @Resource
    TixianMapper tixianMapper;

    public int insert(Tixian tixian) {
        return tixianMapper.insert(tixian);
    }

    public int update(Tixian tixian) {
        return tixianMapper.updateById(tixian);
    }

    public Tixian selectById(int id) {
        return tixianMapper.selectById(id);
    }

    public IPage<Tixian> selectByUserId(long userId, String status, int pageNum, int pageSize) {
        IPage<Tixian> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Tixian> wrapper = new QueryWrapper<>();
        wrapper.eq("userId", userId);
        wrapper.eq(status != null, "status", status);
        wrapper.orderByDesc("id");
        return tixianMapper.selectPage(page, wrapper);

    }

    public IPage<Tixian> getList(Long userId, String startTime, String endTime, String status,
        int pageNum, int pageSize) {
        IPage<Tixian> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Tixian> wrapper = new QueryWrapper<>();
        wrapper.eq(userId != null, "userId", userId);
        wrapper.ge(startTime != null, "addTime", startTime);
        wrapper.lt(startTime != null, "addTime", endTime);
        wrapper.eq(status != null, "status", status);

        return tixianMapper.selectPage(page, wrapper);
    }
}
